<?php
require_once dirname(__FILE__) . '/../includes/common.inc.php';
require_once dirname(__FILE__) . '/../includes/pdoorm.inc.php';

header('Content-Type: text/plain');
die;

$sql="SELECT UNIX_TIMESTAMP(a.customer_date) as cdate,UNIX_TIMESTAMP(a.work_date) as wdate,a.* FROM customer as a WHERE 1=1 ";
$customerarr = getall($sql,1);

//print_r($customerarr);

 foreach ($customerarr as $onecus)
 {
 	$unique = MiscUtils::unique();
 	$onecus['cancel_message'] = empty($onecus['cancel_message'])? '0' :$onecus['cancel_message'];
 	
 	
 	  $cusarr = array(
 	                  'e_oid' => $onecus['customer_id'],
 	                  'trackId' => $unique,
 	                  'createdDate' => $onecus['cdate'],
 	                  'bridename' => $onecus['bride_name'],
 	                  'brideaddrLn1' => $onecus['bride_address'],
 	                  'brideaddrLn2' => $onecus['bride_address1'],
 	                  'bridephone' => $onecus['bride_phone'],
 	                  'bridemobile' => $onecus['bride_mobile'],
 	                  'brideemail' => $onecus['bride_email'],
 	                  'groomname' => $onecus['groom_name'],
 	                  'groomaddrLn1' => $onecus['groom_address'],
 	                  'groomaddrLn2' => $onecus['groom_address1'],
 	                  'groomphone' => $onecus['groom_phone'],
 	                  'groommobile' => $onecus['groom_mobile'],
                      'groomemail' => $onecus['groom_email'],
                      'note' => $onecus['customer_note'],
                      'source' => getSourceName($onecus['customer_source']),
                      'reminderNote' => $onecus['officer_note'],
                      'cancelled' => 0,
                      'cancelledMessage' => $onecus['cancel_message'],
                      'cancelledDate' => 0,
                      'cancelledOperator' =>'' 
 	                  );
 	                  
 	                  
 	                 $customer_id = insert('ns_v1customer',$cusarr);
 	                 
 	                 
           switch ($onecus['wedding_album_detail']) 
           {
           	   case'12x18 inch Album':
           	   	$walbum = 'with Album 12x18';
           		   break;
           		   
               case'8x12 inch Album':
                $walbum = 'with Album 12x8';
                   break;
                   
               case'18X18 inch Album':
                $walbum = 'with Album 18X18';
                   break;
                   
               default:
               	  $walbum = '';
               	  break;                                		
           	
           }

                       /*echo 'wedding_photography_detail:'.$onecus['wedding_photography_detail']."\n";
                        echo 'wedding_video_detail:'.$onecus['wedding_video_detail']."\n";
                        if(trim($onecus['wedding_photography_detail']) !=''){echo"no-no";}
                        if(empty($onecus['wedding_photography_detail'])) {echo"i am NULL";}*/
                        $photopackage ='';
                        $videopackage ='';
           
           if($walbum ==''){
           	
	           if($onecus['customer_type'] == 'wedding' && substr($onecus['customer_date'],0,10)< '2010-05-22' &&
	               !empty($onecus['wedding_photography_detail']))
	              {
	              	$photopackage = 'Wedding Photo '.$onecus['wedding_photography_detail'].' (old)';
	              }
	              
	            if($onecus['customer_type'] == 'wedding' && substr($onecus['customer_date'],0,10)>= '2010-05-22' &&
	               !empty($onecus['wedding_photography_detail']))
	              {
	                $photopackage = 'Wedding Photo '.$onecus['wedding_photography_detail'];
	              }
              
           }else{
                  if($onecus['customer_type'] == 'wedding' && substr($onecus['customer_date'],0,10)< '2010-05-22' &&
                   !empty($onecus['wedding_photography_detail']))
                  {
                    $photopackage = 'Wedding Photo '.$onecus['wedding_photography_detail'].' '.$walbum.' (old)';
                  }
                  
                if($onecus['customer_type'] == 'wedding' && substr($onecus['customer_date'],0,10)>= '2010-05-22' &&
                   !empty($onecus['wedding_photography_detail']))
                  {
                    $photopackage = 'Wedding Photo '.$onecus['wedding_photography_detail'].' '.$walbum;
                  }           	
           	
           }
           
           
                  if($onecus['customer_type'] == 'pre-wedding' && substr($onecus['customer_date'],0,7)< '2010-02' &&
                   !empty($onecus['wedding_photography_detail']))
                  {
                    $photopackage = '2009 Pre-wedding Photo '.$onecus['wedding_photography_detail'].' (old)';
                  }
              
              
                  if($onecus['customer_type'] == 'pre-wedding' && substr($onecus['customer_date'],0,7)>= '2010-02' &&
                     substr($onecus['customer_date'],0,7)< '2011-03' && !empty($onecus['wedding_photography_detail']))
                  {
                    $photopackage = '2010 Pre-wedding Photo '.$onecus['wedding_photography_detail'].' (old)';
                  }

                  if($onecus['customer_type'] == 'pre-wedding' && substr($onecus['customer_date'],0,7)>= '2011-03' &&
                     !empty($onecus['wedding_photography_detail']))
                  {
                    $photopackage = 'Pre-wedding Photo '.$onecus['wedding_photography_detail'];
                  }  

                  
                  if($onecus['customer_type'] == 'portrait' &&
                     !empty($onecus['wedding_photography_detail']))
                  {
                    $photopackage = 'Portrait '.$onecus['wedding_photography_detail'];
                  }

                  
             
               if($onecus['customer_type'] == 'wedding' && substr($onecus['customer_date'],0,10)< '2010-05-22' &&
                   !empty($onecus['wedding_video_detail']))
                  {
                    $videopackage = 'Wedding Video '.$onecus['wedding_video_detail'].' (old)';
                  }
                  
                if($onecus['customer_type'] == 'wedding' && substr($onecus['customer_date'],0,10)>= '2010-05-22' &&
                   !empty($onecus['wedding_video_detail']))
                  {
                    $videopackage = 'Wedding Video '.$onecus['wedding_video_detail'];
                  }
                  
                  
                  
                  switch ($onecus['customer_type'])
                  {
                  	case'wedding':
                  		$uptype = 'Wedding';
                  	   break;
                  	   
                  	case'pre-wedding':
                  		$uptype = 'Prewedding';
                  		break;
                  		   
                    case'portrait':
                        $uptype = 'Portrait';
                        break; 
                    default:
                    	$uptype = '';
                    	break;
                    	                	
                  }
                  
                  /*photopackege info*/
                  $photopackageinfo = getPackageInfo($photopackage,$onecus['wedding_photography_price']);
                  
                  $videopackageinfo = getPackageInfo($videopackage,$onecus['wedding_video_price']);
                  
                  
                  
                  $photoor = isset($videopackageinfo['original']) ? $videopackageinfo['original'] :0;
                  $videoor = isset($photopackageinfo['original']) ? $photopackageinfo['original'] :0;
                  
                  
                  $tmp = ( abs($photoor+ $videoor-$onecus['total_price'])/(($photoor+ $videoor)== 0 ? 1 :($photoor+ $videoor) ) )*100;
                  $discount = round($tmp,2);
                  
                  $myorderarr = array(
				                    //'e_oid' => NULL,
                                    'trackId' => MiscUtils::unique(),
								    'createdDate' => $onecus['cdate'],
								    'flag' => $uptype,
								    'type' => $uptype,
								    'date' => $onecus['wdate'],
								    'disposaldate' =>0 ,
								    'disposaluserAccount' => '',
								    'disposalstatus' =>0 ,
								    'disposalmessage' => $onecus['cancel_message'],
								    'price' => $onecus['total_price'],
								    'photoname' => $photopackage,
								    'photoprice' => isset($photopackageinfo['price']) ? $photopackageinfo['price'] :0,
								    'photohours' => isset($photopackageinfo['hours']) ? $photopackageinfo['hours']:0,
								    'photopersons' => isset($photopackageinfo['persons']) ? $photopackageinfo['persons'] :0,
								    'photomakeup' => isset($photopackageinfo['makeup']) ? $photopackageinfo['makeup'] :0,
								    'photooriginal' => isset($photopackageinfo['original']) ? $photopackageinfo['original'] :0,
								    'videoname' => $videopackage,
								    'videoprice' => isset($videopackageinfo['price']) ? $videopackageinfo['price']:0,
								    'videohours' => isset($videopackageinfo['hours']) ? $videopackageinfo['hours']: 0,
								    'videopersons' => isset($videopackageinfo['persons']) ? $videopackageinfo['persons'] :0,
								    'videomakeup' => isset($videopackageinfo['makeup']) ? $videopackageinfo['makeup'] :0,
								    'videooriginal' => isset($videopackageinfo['original']) ? $videopackageinfo['original'] :0,
								    'note' => $onecus['officer_note'],
								    'customerId' => $onecus['customer_id'],
								    'finished' => 0,
								    'discount' => $discount,
								    'isOrderDiscountSolved' => 0,
								    'isPayment1FirstSolved' => 0,
								    'isPayment1SecondSolved' =>0 ,
								    'isPayment1ThirdSolved' => 0,
								    'isPayment1ForthSolved' => 0,
								    'isPayment2FirstSolved' => 0,
								    'isPayment2SecondSolved' =>0 ,
								    'isPayment3FirstSolved' => 0,
								    'isPayment3SecondSolved' =>0 ,
								    'isPayment4Solved' => 0,
								    'isNoWeddingDaySolved' => 0,
                                    'phototrackId' => isset($photopackageinfo['trackId']) ? $photopackageinfo['trackId'] :'',
                                    'videotrackId' =>isset($videopackageinfo['trackId']) ? $videopackageinfo['trackId'] :''
                                     );
                      
                                     //print_r($myorderarr);
                                     //echo "\n";
                      $order_id = insert('ns_v1myorder',$myorderarr);
                      
                      
                      if(!empty($photopackageinfo))
                      {
                      	 //print_r($photopackageinfo);
                      	 $photopurchasearr = getPurchaseItem($photopackageinfo['e_oid']);
                      	 //print_r($photopurchasearr);
                      	 
                      	 if(!empty($photopurchasearr))
                      	 {
                      	 	foreach ($photopurchasearr as $onepur)
                      	 	{
                                     $purchasearray = array(
                                                         //'e_oid' => NULL,
                                                         'trackId' => MiscUtils::unique(),
                                                         'cancelled' => 0,
                                                         'sampleId' => $onepur['sample_id'],
                                                         'name' => $onepur['name'],
                                                         'price' => $onepur['price'],
                                                         'unit' => $onepur['unit'],
                                                         'type' => $onepur['type'],
                                                         'model' => $onepur['model'],
                                                         'otherId' => $onepur['otherId'],
                                                         'quantity' => $onepur['quantity'],
                                                         'total' => $onepur['total'],
                                                         'packageInc' => 'Photo Package',
                                                         'isFree' => 0,
                                                         'urgent' => 0,
                                                         'order_id' => $order_id                         
                                                     );  

                                                      $purchaseone_id = insert('ns_v1purchaseitem',$purchasearray);
                                                      $puritemselectarr = getPurchaseItemSelect($onepur['e_oid']);
                                                      
                                                      if(!empty($puritemselectarr))
                                                      {
                                                      	foreach ($puritemselectarr as $onepurs)
                                                      	{
                                                      		$pselectarr = array(
                                                      		                   //'e_oid' =>NULL,
                                                      		                   'trackId' =>MiscUtils::unique(),
                                                      		                   'title' =>$onepurs['title'],
                                                      		                   'value' =>$onepurs['value'],
                                                      		                   'purchaseitem_id' =>$purchaseone_id
                                                      		                   );
                                                      		                   
                                                      		             insert('ns_v1purchaseitemselect',$pselectarr);      
                                                      	}
                                                      }//purchaseitemselect end
                                                      
                                                      //print_r($puritemselectarr);
                      	 		
                      	 	}
                      	 }//photo package end

                      	 
                      	 
                      	 
                      	     //增加photographer
                            $fenmu = empty($photopackageinfo['persons']) ? 1 : $photopackageinfo['persons'];
						    $perhours = $photopackageinfo['hours']/$fenmu;
						    
						    $sqlpoto = "SELECT * FROM ns_v1sample WHERE `name` = 'Single Photographer With Hours'";
						    $photoarr = getall($sqlpoto,1);
						    $total = $photoarr[0]['price']*$perhours;
						    
						    for($i=0;$i< $photopackageinfo['persons'];$i++)
						    {
						        //$unique = MiscUtils::unique();
						        
						          $photographerarr =array(
						                                 //'e_oid' => NULL,
						                                 'trackId' => MiscUtils::unique(),
						                                 'cancelled' => 0,
						                                 'sampleId' => $photoarr[0]['e_oid'],
						                                 'name' => $photoarr[0]['name'],
						                                 'price' => $photoarr[0]['price'],
						                                 'unit' => $photoarr[0]['unit'],
						                                 'type' => $photoarr[0]['type'],
						                                 'model' => $photoarr[0]['model'],
						                                 'otherId' => MiscUtils::unique(),
						                                 'quantity' => $perhours,
						                                 'total' => $total,
						                                 'packageInc' => 'Photo Package',
						                                 'isFree' => 0,
						                                 'urgent' => 0,
						                                 'order_id' => $order_id
						                              
						                                  );
						                                  $purchase_id = insert('ns_v1purchaseitem',$photographerarr);
						                                  
						                                  
						                                  
						                                  //print_r($photographerarr);
						        
						        /*$potographer = "insert into ns_v1purchaseitem value (NULL,'{$unique}','0','{}','{}','{}',
						                                                                   '{}','{}','{}','{$unique}','{$perhours}',
						                                                                   '{$total}','Photo Package','0','0','{$onecus['e_oid']}')";
						                                                                   */
						        //sql_execute($potographer);
						    }
						    
						     unset($fenmu);
                             unset($perhours);
                             unset($total);
                             unset($i);

						   //增加photographer结束 
                      	
                      }
                      
                       unset($onepur);
                       
                      //videopackage add
                       if(!empty($videopackageinfo))
                      {
                         //print_r($photopackageinfo);
                         $videopurchasearr = getPurchaseItem($videopackageinfo['e_oid']);
                         //print_r($photopurchasearr);
                         
                         if(!empty($videopurchasearr))
                         {
                            foreach ($videopurchasearr as $onepur)
                            {
                                     $vpurchasearray = array(
                                                         //'e_oid' => NULL,
                                                         'trackId' => MiscUtils::unique(),
                                                         'cancelled' => 0,
                                                         'sampleId' => $onepur['sample_id'],
                                                         'name' => $onepur['name'],
                                                         'price' => $onepur['price'],
                                                         'unit' => $onepur['unit'],
                                                         'type' => $onepur['type'],
                                                         'model' => $onepur['model'],
                                                         'otherId' => $onepur['otherId'],
                                                         'quantity' => $onepur['quantity'],
                                                         'total' => $onepur['total'],
                                                         'packageInc' => 'Video Package',
                                                         'isFree' => 0,
                                                         'urgent' => 0,
                                                         'order_id' => $order_id                         
                                                     );  

                                                      $purchaseone_id = insert('ns_v1purchaseitem',$vpurchasearray);
                                                      $vpuritemselectarr = getPurchaseItemSelect($onepur['e_oid']);
                                                      
                                                      if(!empty($vpuritemselectarr))
                                                      {
                                                        foreach ($vpuritemselectarr as $onepurs)
                                                        {
                                                            $vpselectarr = array(
                                                                               //'e_oid' =>NULL,
                                                                               'trackId' =>MiscUtils::unique(),
                                                                               'title' =>$onepurs['title'],
                                                                               '`value`' =>$onepurs['value'],
                                                                               'purchaseitem_id' =>$purchaseone_id
                                                                               );
                                                                               
                                                                         insert('ns_v1purchaseitemselect',$vpselectarr);      
                                                        }
                                                      }//purchaseitemselect end
                                                      
                                                      //print_r($puritemselectarr);
                                
                            }
                         }//video package end


                         
                         
                             //增加videographer
                            $fenmu = empty($videopackageinfo['persons']) ? 1 : $videopackageinfo['persons'];
                            $perhours = $videopackageinfo['hours']/$fenmu;
                            
                            $sqlvideo = "SELECT * FROM ns_v1sample WHERE `name` = 'Single Videographer With Hours'";
                            $videoarr = getall($sqlvideo,1);
                            $total = $videoarr[0]['price']*$perhours;
                            
                            for($i=0;$i< $videopackageinfo['persons'];$i++)
                            {
                                //$unique = MiscUtils::unique();
                                
                                  $videographerarr =array(
                                                         //'e_oid' => NULL,
                                                         'trackId' => MiscUtils::unique(),
                                                         'cancelled' => 0,
                                                         'sampleId' => $videoarr[0]['e_oid'],
                                                         'name' => $videoarr[0]['name'],
                                                         'price' => $videoarr[0]['price'],
                                                         'unit' => $videoarr[0]['unit'],
                                                         'type' => $videoarr[0]['type'],
                                                         'model' => $videoarr[0]['model'],
                                                         'otherId' => MiscUtils::unique(),
                                                         'quantity' => $perhours,
                                                         'total' => $total,
                                                         'packageInc' => 'Video Package',
                                                         'isFree' => 0,
                                                         'urgent' => 0,
                                                         'order_id' => $order_id
                                                      
                                                          );
                                                          $purchase_id = insert('ns_v1purchaseitem',$videographerarr);
                                                          
                                                          
                                                          
                                                          //print_r($photographerarr);
                                
                                /*$potographer = "insert into ns_v1purchaseitem value (NULL,'{$unique}','0','{}','{}','{}',
                                                                                           '{}','{}','{}','{$unique}','{$perhours}',
                                                                                           '{$total}','Photo Package','0','0','{$onecus['e_oid']}')";
                                                                                           */
                                //sql_execute($potographer);
                            }
                             unset($fenmu);
                             unset($perhours);
                             unset($total);
                             unset($i);

                           //增加photographer结束 
                        
                      }                      

                      /**
                       * additions
                       * 
                       */
                                 /* switch()
                                  {
                                  	case 'extra hours video':
                                  	case 'Xtra hour for photo':
                                  		$samname = 'Extra hour for video';
                                  		break;
                                    case 'extra hours photo':
                                    case 'Xtra hour for photo':	
                                        $samname = 'Extra hour for photo';
                                        break;
                                    case :
                                        $samname = '';
                                        break;
                                    case :
                                        $samname = '';
                                        break;                                                                                                                 		
                                  }*/
                                  
                             addtion($onecus['addition1_detail'],$onecus['addition1_price'],$order_id);
                             addtion($onecus['addition2_detail'],$onecus['addition2_price'],$order_id);
                             addtion($onecus['addition3_detail'],$onecus['addition3_price'],$order_id);
                             addtion($onecus['addition4_detail'],$onecus['addition4_price'],$order_id);
                             addtion($onecus['addition5_detail'],$onecus['addition5_price'],$order_id);
                             addtion($onecus['addition6_detail'],$onecus['addition6_price'],$order_id);
                             addtion($onecus['addition7_detail'],$onecus['addition7_price'],$order_id);
                             addtion($onecus['addition8_detail'],$onecus['addition8_price'],$order_id);
                             addtion($onecus['addition9_detail'],$onecus['addition9_price'],$order_id);
                             addtion($onecus['addition10_detail'],$onecus['addition10_price'],$order_id);
                                                     
                      
                      //echo $photopackage."\n";
                      //echo $videopackage."\n";	                 
 	                  //print_r($cusarr);
 	                  //echo"<br>";
 	
unset($onecus);
unset($videopackage);
unset($photopackage);
unset($uptype);
unset($walbum);
                  unset($photoor);
                  unset($videoor);
                  unset($tmp);
                  unset($discount);
 }

 
 
 
 
 
 
 function insert($table,$arra,$debug='')
 {
 	global  $myPdo;
 	
 	          if(!empty($arra))
 	          {
                $expensevalue = '';
                $fieldsexpense = '';
                
                foreach($arra as $key => $value)
                {
                         $fieldsexpense.= '`'.$key.'`,';
                         $expensevalue .=" '".addslashes($value)."',";                   
                }
                
                //$fieldsexpense .= "cancelledMessage";
                $fieldsexpense =substr($fieldsexpense,0,-1);
                //$expensevalue .= "'0'";
                $expensevalue =substr($expensevalue,0,-1);
                
                $expensesql = " insert into {$table}(".$fieldsexpense.") values(".$expensevalue.")";
                
                if(!empty($debug))
                {
                    echo "EXECUTE SQL:\n".$expensesql."\n";
                    return 0;     
                }else{
                    sql_execute($expensesql);
                    return  lastinsertid();
                } 	
 	          }
 	
 }
 
 function getSourceName ($source_id)
 {
 	global $myPdo;
 	
 	$sql="SELECT source_name FROM customer_source where source_id = '{$source_id}' limit 1";
 	
 	$sourarr = getall($sql,1);
 	
 	return $sourarr[0]['source_name'];
 }

 /**
  * 
  */
 function getPackageInfo($photopackage,$packageprice)
 {
 	global $myPdo;
 	
 	$photopackagesql = "select abs(a.price - {$packageprice}) AS cha,a.* FROM ns_v1package AS a where a.`name` = '{$photopackage}'  ORDER BY cha ASC  limit 1";
                  
    $photopackageinfo = getall($photopackagesql,1);
    
    if(!empty($photopackageinfo))
    {
    	$sqla = "SELECT ifnull(SUM(quantity*total),0) AS total FROM ns_v1packageitem WHERE package_id = '{$photopackageinfo[0]['e_oid']}'";
    	$originalarr = getall($sqla,1);
    	$originalprice = $originalarr[0]['total'] +$photopackageinfo[0]['hours']*180 ;
    	$photopackageinfo[0]['original'] = $originalprice;
        return $photopackageinfo[0];
    }else{
    	 return  $photopackageinfo;
    } 
      
 	         
 }
 
 /**
  * 
  * get purchaseitem
  */
  //SELECT a.sample_id,b.`name`,b.price,b.unit,b.type,b.model,a.otherId,a.quantity,(a.quantity*b.price) AS total,'' AS packageInc,0 AS isFree,0 AS urgent,NULL AS order_id,a.e_oid FROM ns_v1packageitem AS a LEFT JOIN  ns_v1sample AS b ON a.sample_id =b.e_oid; 
  
 function getPurchaseItem($package_id)
 {
 	global $myPdo;
 	
 	$sql="SELECT a.sample_id,b.`name`,b.price,b.unit,b.type,b.model,a.otherId,a.quantity,(a.quantity*b.price) AS total,'' AS packageInc,0 AS isFree,0 AS urgent,NULL AS order_id,a.e_oid
 	 FROM ns_v1packageitem AS a LEFT JOIN  ns_v1sample AS b ON a.sample_id =b.e_oid
 	 where a.package_id = '{$package_id}'
  ";
 	
 	$purchaseiteminfo = getall($sql,1);
 	
 	return $purchaseiteminfo;
 }
 
 /**
  * get purchaseitemselect 
  * 
  */
  function getPurchaseItemSelect ($packageitem_id)
  {
  	global $myPdo;
  	
  	$sql="SELECT * FROM ns_v1packageitemselect WHERE packageitem_id = '{$packageitem_id}'";
  	$psarr = getall($sql,1);
  	
  	return $psarr;
  	
  	
  }
  
  /**
   * sampleattribute
   * @param $packageitem_id
   */
    function getSampleattribute($sample_id)
  {
    global $myPdo;
    
    $sql="SELECT * FROM ns_v1sampleattribute WHERE sample_id = '{$sample_id}'";
    $psarr = getall($sql,1);
    
    return $psarr;
  }
  
    /**
   * sampleattribute
   * @param $packageitem_id
   */
  function getSampleattributeoption($sampleattribute_id)
  {
    global $myPdo;
    
    $sql="SELECT * FROM ns_v1sampleattribute WHERE sample_id= 18;
SELECT aa.e_oid,bb.`name` AS title,aa.`name` AS `value`,aa.sampleattribute_id  FROM ns_v1sampleattributeoption AS aa LEFT JOIN ns_v1sampleattribute AS bb 
ON aa.sampleattribute_id = bb.e_oid
WHERE sampleattribute_id ='{$sampleattribute_id}' ORDER BY aa.e_oid LIMIT 1";
    $psarr = getall($sql,1);
    
    return $psarr;
  }  
 
  /**
   * myPdo 1
   * 
   *
   */
 /**
 * 执行sql
 * */
function sql_execute1($sql){
    global $myPdo1;  
    
    $stmt2 = $myPdo1->prepare($sql);
    $stmt2->execute();

    return;
}
 
 
 
 
 /**
  * 
  * 
  * addtion
  */

  function addtion($addition1_detail,$addition1_price,$order_id)
  {
  	global $myPdo;
  	                            if(empty($addition1_detail)){
  	                            	return ;
  	                            }
  	
                                  if( strpos($addition1_detail,'extra hours video') || strpos($addition1_detail,'Xtra hour for video'))
                                  {
                                     $samname = 'Extra hour for video';
                                  }
                                  
                                  if(strpos($addition1_detail,'Xtra hour for photo') || strpos($addition1_detail,'extra hours photo') )
                                  {
                                     $samname = 'Extra hour for photo';
                                  }
                                  
                                  if(strpos($addition1_detail,'Thank You Cards'))
                                  {
                                     $samname = 'Thank You Card (photo & card)';
                                  }
                                  
                                   if(strpos($addition1_detail,'Makeup Fee'))
                                  {
                                     $samname = 'makeup artist with package(10hours)';
                                  } 

                                   if(strpos($addition1_detail,'Xtra Videographer'))
                                  {
                                     $samname = 'Extra Videographer With Hours(3hrs Minimum)';
                                  } 

                                   if(strpos($addition1_detail,'Xtra Photographer'))
                                  {
                                     $samname = 'Extra photographer With Hours(3hrs Minimum)';
                                  }
                                  
                                  if(strpos($addition1_detail,'16x24 inch canvas'))
                                  {
                                     $samname = 'Canvas 16x24';
                                  }
                                  
                                   if(strpos($addition1_detail,'24x36 inch Canvas'))
                                  {
                                     $samname = 'Canvas 24x36';
                                  }                                  
                                  
                                   if(strpos($addition1_detail,'5x7 Inch album'))
                                  {
                                     $samname = 'Album 5x7(10P)';
                                  }

                                  
                                    if(strpos($addition1_detail,'12x18 inch Album'))
                                  {
                                     $samname = 'Album 12x18 (10P)';
                                  }                                  
                                  
                                    if(strpos($addition1_detail,'8x12 inch Album'))
                                  {
                                     $samname = 'Album 12x8 (15P)';
                                  }                                      
                                  
                                  
                                    if(strpos($addition1_detail,'12X12 inch Album'))
                                  {
                                     $samname = 'Album 12X12 (10P)';
                                  }                                    
                                  
                                    if(strpos($addition1_detail,'18X18 inch Album'))
                                  {
                                     $samname = 'Album 18x18 (10P)';
                                  }                                    
                                  
                                  if(strpos($addition1_detail,'7X7inch Album'))
                                  {
                                     $samname = 'Album 7x7';
                                  }                                       
                                  
                                  if(strpos($addition1_detail,'4x6 Inch Album'))
                                  {
                                     $samname = 'Album 4x6';
                                  } 
                                  if(!isset($samname)) $samname = $addition1_detail;
                                  
                                  
                                  
                                     $sqladdition = "SELECT * FROM ns_v1sample WHERE `name` = '{$samname}'";
                                     $additionarr = getall($sqladdition,1);                                 
                                  
                                  
                                   $vpurchasearray = array(
                                                         //'e_oid' => NULL,
                                                         'trackId' => MiscUtils::unique(),
                                                         'cancelled' => 0,
                                                         'sampleId' => isset($additionarr['e_oid']) ? $additionarr['e_oid'] : 0,
                                                         'name' => isset($additionarr['name']) ? $additionarr['name'] : $addition1_detail,
                                                         'price' => isset($additionarr['price']) ? $additionarr['price'] : $addition1_price,
                                                         'unit' => isset($additionarr['unit']) ? $additionarr['unit'] : '',
                                                         'type' => isset($additionarr['type']) ? $additionarr['type'] : SAMPLE_TYPE_OTHER,
                                                         'model' => isset($additionarr['model']) ? $additionarr['model'] : '',
                                                         'otherId' => MiscUtils::unique(),
                                                         'quantity' => 1,
                                                         'total' => $addition1_price,
                                                         'packageInc' => '',
                                                         'isFree' => 0,
                                                         'urgent' => 0,
                                                         'order_id' => $order_id                         
                                                     ); 

                                                     $addpurchaseitem_id = insert('ns_v1purchaseitem',$vpurchasearray);
                                                     
                                     if(isset($additionarr['e_oid']))
                                     {
                                        $smpattribute = getSampleattribute($additionarr['e_oid']);
                                        
                                        if(!empty($smpattribute))
                                        {
                                            foreach ($smpattribute as $onebute)
                                            {
                                                $sampleoption = getSampleattributeoption($onebute['e_oid']);
                                                
                                                if(!empty($sampleoption)){
                                                    
                                                             $addpselectarr = array(
                                                                               //'e_oid' =>NULL,
                                                                               'trackId' =>MiscUtils::unique(),
                                                                               'title' =>$sampleoption[0]['title'],
                                                                               '`value`' =>$sampleoption[0]['value'],
                                                                               'purchaseitem_id' =>$addpurchaseitem_id
                                                                               );
                                                                               
                                                                         insert('ns_v1purchaseitemselect',$addpselectarr); 
                                                }                                               
                                                
                                                
                                            }
                                        }
                                        
                                        
                                     } //sampleattributeoptions        	
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

?>